import { Service } from "cl-admin";
import BaseService from "@/service/base";
@Service("order")
class Order extends BaseService {
	// 分页列表
	page({ onsumption, size, dept_id = [], bra_id = [], ...args }) {
		let params = {
			search_type: 0,
			pagesize: size,
			dept_id: dept_id.join(),
			bra_id: bra_id.join(),
			...args
		};
		if (onsumption && onsumption.length) {
			params.btime = onsumption[0];
			params.etime = onsumption[1];
			params.time_type = 66;
		}
		return this.$get("/lists", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 新增
	add(data) {
		return Promise.resolve();
	}
	// 更新，包含 id
	update(params) {
		return this.$post("/edit", params);
	}
	// 订单修改内容
	editInfo(params) {
		return this.$get("/getEditInfo", { params });
	}
	// 删除，ids = [1, 2, 3]
	remove({ ids }) {
		return Promise.resolve();
	}
	// 客户订单
	cusDetail(params) {
		return this.$get("/cusGetDetail", { params });
	}
	//订单重置
	resetOrder(params) {
		return this.$post("/resetOrder", params);
	}
	// 分期订单清账
	liquiDate(params) {
		return this.$post("/liquidate", params);
	}
	// 退款
	lyrefund(params) {
		return this.$post("/lyrefund", params);
	}
	// 分期订单
	stages({ bra_id = [], date = [], ...args }) {
		let params = {
			bra_id: bra_id.join(),
			btime: date[0],
			etime: date[1],
			...args
		};
		return this.$get("/stages", { params }).then(res => {
			console.log("res", res);
			return {
				list: res.data,
				pagination: {
					...params,
					total: res.total
				}
			};
		});
	}
	maintainList(params) {
		return this.$get("/maintainList", { params: this.advancesParams(params) });
	}
	// 预收款报表
	advances({ bra_id = [], date = [], ...args }) {
		let params = {
			...args
		};
		if (bra_id) {
			params.bra_id = bra_id.join();
		}
		if (date) {
			params.btime = date[0];
			params.etime = date[1];
		}
		return this.$get("/advances", { params }).then(res =>
			this.pagination(params, { data: res.list, ...res })
		);
	}

	// 未到店补色客户列表总数
	maintainlisttotal(params) {
		return this.$get("/maintainlisttotal", { params: this.advancesParams(params) });
	}

	advancesParams({ bra_id = [], date = [], ...args }) {
		let params = {
			...args
		};
		if (bra_id) {
			params.bra_id = bra_id.join();
		}
		if (date) {
			params.btime = date[0];
			params.etime = date[1];
		}
		return params;
	}
	// 财务预收款
	advance({ time = [], ...args }) {
		let params = {
			...args
		};
		if (time) {
			params.begin = time[0];
			params.end = time[1];
		}
		return this.$get("/advance", { params }).then(res => {
			console.info("res9999", res);
			return {
				data_list: res.data_list,
				data_title: res.data_title,
				pagination: {
					...params,
					total: res.total
				},
				data_total: res.data_total
			};
		});
	}
	cancelLyRefund(params) {
		return this.$post("/cancelLyRefund", params);
	}
	updateSource(params) {
		return this.$post("/updateSource", params);
	}
  updateTeachers(params) {
		return this.$post("/updateTeachers", params);
	}

}
export default Order;
